var api = require("../../../../api.js"),
  app = getApp();
Page({
  data: {
    levelArr: [],
    head:wx.getStorageSync('head'),
    data:'',
    icons: '',
    juli: '',
  }, 
  onLoad: function () {
    let _this = this;
    var uid = wx.getStorageSync('uid');
    var that = this 
    that.setData({
      icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
    })
    app.request({
      url: api.member.show,
      data: {
        uid: uid
      },
      method: 'post',
      success: function (res) {
        console.log('rererea', res.data)
        var data = res.data
        let _levelArr = [];
        let zong = '';
        if (data.member_grade == 1) { zong = 1000 }
        else if (data.member_grade == 2) { zong = 2000 }
        else if (data.member_grade == 3) { zong = 3000 }
        else if (data.member_grade == 4) { zong = 4000 }
        else if (data.member_grade == 5) { zong = 5000 };
        let _juli = zong - data.hyintegral
        let _maxScore = 5000; // 最大成长值
        let _currentScore = data.hyintegral;  // 当前成长值
        let _progressPercent = 100 / _maxScore * _currentScore;  // 进度条位置
        let _mark = 700 / 100 * _progressPercent - 65 / 2;
        for (let i = 1; i < 6; i++) {
          _levelArr.push({
            defaultImg: that.data.icons+'/resource/common/image/customer/member-center/level' + i + '.png',
            activeImg: that.data.icons +'/resource/common/image/customer/member-center/level' + i + '_1.png',
            needScore: _maxScore / 5 * (i - 1)
          });
        }
        if (_juli == 0) {
          _juli = 1000;
        }
        res.data.juli = _juli;
        _this.setData({
          levelArr: _levelArr,
          currentScore: _currentScore,
          progressPercent: _progressPercent,
          mark: _mark,
          data: res.data,
        });
      }
    })
  },
  onShow: function () {
    var that = this
    var uid = wx.getStorageSync('uid');
    app.request({
      url: api.member.show,
      data: {
        uid: uid
      },
      method: 'post',
      success: function (res) {
        console.log('rerere', res)
        var data = res.data
        let zong = '';
        if (data.member_grade == 1) { zong = 1000 }
        else if (data.member_grade == 2) { zong = 2000 }
        else if (data.member_grade == 3) { zong = 3000 }
        else if (data.member_grade == 4) { zong = 4000 }
        else if (data.member_grade == 5) { zong = 5000 };
        let juli = zong - data.hyintegral;
        if (juli == 0) {
          juli = 1000;
        }
        res.data.juli = juli;
        that.setData({
          data: res.data,
        })
      }
    })
  },
})